package com.three.lab.fragment;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;
import android.widget.TextView;

import com.three.lab.R;
import com.three.lab.adapter.NewFriendAdapter;
import com.three.lab.base.AppConstant;
import com.three.lab.base.BaseFragment;
import com.three.lab.bean.NewFriendBean;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MessageFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MessageFragment extends BaseFragment {

    private TextView textView,tvTitle;
    private RecyclerView recyclerView;
    private NewFriendAdapter newFriendAdapter;
    private List<NewFriendBean> newFriendBeanList;

    public static MessageFragment newInstance(int index, String title) {
        MessageFragment fragment = new MessageFragment();
        Bundle args = new Bundle();
        args.putInt(AppConstant.INDEX, index);
        args.putString(AppConstant.INDEX_NAME, title);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initArguments(Bundle bundle) {}

    @Override
    protected int bindLayout() {
        return R.layout.fragment_message;
    }

    @Override
    protected void initViews(View view, Bundle savedInstanceState) {
        tvTitle = $(R.id.tv_title);
        tvTitle.setText(R.string.message);
        textView = $(R.id.tv_msg);
        $(R.id.iv_left).setVisibility(View.GONE);
        String text = "    There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! \n     When the door of happiness closes, another opens, but often times we look so long at the closed door that we dont see the one which has been opened for us. \n     Dont go for looks; they can deceive. Dont go for wealth; even that fades away. Go for someone who makes you smile because it takes only a smile to make a dark day seem bright. Find the one that makes your heart smile. \n     Dream what you want to dream; go where you want to go; be what you want to be, because you have only one life and one chance to do all the things you want to do. \n    You’ve probably heard the old saying “The grass is always greener on the other side of the fence.” \n    Perhaps you feel like it’s true. You look at other people’s lives, and you envy them. They seem to be doing so much better than you. They’ve got a great job. Lots of money. A happy home life. They seem to have it all. And you can’t help wishing that you did, too. \n    But none of us ever really know what it’s like to live someone else’s life. No-one’s life is perfect – whatever it looks like from the outside. \n    Plus, it’s a safe bet that some of your friends are looking at your life and thinking very similar things. Whatever state your life is in, you’ve got a lot of good things. You just need to recognize them again.";
        textView.setText(text);

        recyclerView = $(R.id.recyclerView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false);
        recyclerView.setLayoutManager(linearLayoutManager);
        newFriendAdapter = new NewFriendAdapter();
        recyclerView.setAdapter(newFriendAdapter);
    }

    @Override
    public void initListener() {}

    @Override
    public void widgetClick(View v) {}

    @Override
    protected void initData(Context context) {
        newFriendBeanList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            NewFriendBean bean = new NewFriendBean(i,"张晓玲" + i);
            newFriendBeanList.add(bean);
        }
        newFriendAdapter.setNewData(newFriendBeanList);
    }
}